Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to change button colors via Core Graphics. #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

cconstable
Copy link

This pull will not affect any apps currently using SIAlertView. It adds opt-in features.

That said, this is a relatively big change so don't feel obligated to merge it if you don't want to :)

I wanted to change some of the characteristics (color, shadow, etc) of the buttons but I noticed they were images. I tried to replicate them a closely and as I could using core graphics so the background, shadow, and virtually any other property can be easily changed.

By default, SIAlertView still uses the images. However, if you want to customize the buttons you can use UIAppearance like so:

[[SIAlertView appearance] setUseCoreGraphics:1];
[[SIAlertView appearance] setDefaultButtonColor:[UIColor colorWithRed:18.0f / 255.0f
                                                                    green:138.0f / 255.0f
                                                                     blue:177.0f / 255.0f
                                                                    alpha:1.0]];
[[SIAlertView appearance] setDefaultButtonFontColor:[UIColor whiteColor]];
[[SIAlertView appearance] setDestructiveButtonColor:[UIColor superBrightRedColor]];

// etc...

Here's a sample:
ios simulator screen shot may 31 2013 7 17 54 pm

I've only exposed a few properties but I think moving to Core Graphics could make SIAlertView really powerful. I'd love to continue adding to it after this.

Let me know your thoughts / concerns!

@cconstable
Copy link
Author

Also, writing this felt a bit weird to me at first:

[[SIAlertView appearance] setUseCoreGraphics:1];

but here are my reasons:

  1. The appearance proxy does not support BOOL
  2. That is a property that directly relates to the appearance of the object.
  3. It's a property users will more than likely want to apply to all SIAlertViews.

@skull-squadron
Copy link

Awesome. I might mod this myself even further w/ a category for FlatUIKit support. :)

@cconstable
Copy link
Author

Hmm FlatKit looks pretty awesome except that the Action Sheet mimics the default API. I think it would be cool to include something like this too (optionally maybe): https://github.com/bennyguitar/Colours-for-iOS

@ghost
Copy link

ghost commented Jun 8, 2013

Would it be possible to make the buttons look pressed when you tap them, I think that got lost, the CG buttons dont appear to change state when pressed

@cconstable
Copy link
Author

Thanks for catching that! Ill make the update on the next day or two.

@jessesquires
Copy link

Hey @mstrchrstphr -- this is awesome. I just submitted a pull-request (see #13) with a bunch of refactoring.

I was planning on doing exactly what you've done here, but I first wanted to get rid of this ridiculous "god class" to make it easier and more manageable.

If you want to submit a pull request for my fork with these changes, I would really appreciate it! My changes include a new SIAlertButton subclass of UIButton so it should be super easy to throw your drawing code in there!

If you don't have time, I could add these changes myself. But I just wanted to let you know about my changes as well.

-- Jesse

P.S. I don't give a shit about backwards compatibility because it won't affect the project that I'm using this in. I want to do everything in CoreGraphics and remove that resource bundle to reduce binary size.

@cconstable
Copy link
Author

@jessesquires NICE!

haha I was actually going to refactor some more but I didn't have time. I'll try to get to this this week! I'm out at WWDC so if I don't get to it before you'd like feel free to grab it :)

My reason for not using Core Graphic for default was because the Core Graphics images are not exactly the same but very close and I figured it would give the pull request a better chance of getting merged upstream.

@jessesquires
Copy link

@mstrchrstphr so jealous about WWDC! i'll be pushing these changes this afternoon!

@jessesquires
Copy link

Just pushed these updates to my fork. I didn't try to mimic the original colors, but added more awesome ones. I also left the original images as an option.

Let me know what you think!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants